﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using d1Common.WebController;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using d1Common;

namespace d1Project.Modules.Common.do4A.Controllers.a1
{
    [Route("do4A/a1/MyInformation")]
    public class MyInformationController : Authorize1Controller
    {
        protected override DbContext dbContext
        {
            get
            {
                return this.db;
            }
        }
        private do4ADbContext db = new do4ADbContext();

        public async Task<IHttpActionResult> Get()
        {
            var entity = await db.User1s.FindAsync(this.UserId);
            if (entity == null) this.Error("当前用户不存在");
            return Ok(entity);
        }

        public async Task<IHttpActionResult> Put(MyInformationPutVm model)
        {
            var entity = await db.User1s.FindAsync(this.UserId);
            if (entity == null) this.Error("当前用户不存在");
            entity.Icon = model.Icon;
            await db.SaveChangesAsync();
            return Ok();
        }
    }

    public class MyInformationPutVm
    {
        public string Icon { get; set; }
    }
}